<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="!crud.props.searchToggle">
        <el-form size="small" label-width="120px" v-formkey="{query:toQuery}">
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="业务日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.startTime"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.endTime"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="费用单据编号">
                <el-input v-model="query.feeOrderCode" placeholder="请输入费用单据编号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="费用收支单据编号">
                <el-input v-model="query.sourceCode" placeholder="请输入费用收支单据编号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="往来单位">
                <zSelect :value.sync="query.customerId" :label="query.customerName"
                         url="api/dropDown/basCustomerList" style="width: 100%;"/>
              </el-form-item>
            </el-col>
          </el-row>
            <el-row :gutter="10" >
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="部门">
                <zSelect :value.sync="query.deptId" :label="query.deptName"
                         url="api/dropDown/childSysDeptList"
                         @change="changeDept"
                         style="width:  100%"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="人员">
                <zSelect :value.sync="query.userId" :label="query.userName" url="api/dropDown/sysUserList"
                         :params="userParams"
                         style="width:  100%;"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="费用收支方式">
                <el-select v-model="query.payBackType" class="filter-item" clearable placeholder="状态" size="small"
                           style="width: 100%;">
                  <el-option
                    v-for="item in dict.t_fee_back_type"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10" style="margin-bottom: 10px">
            <el-col :xs="24" :sm="24" :md="16" :lg="18" :xl="18">
              <el-form-item label="备注">
                <el-input v-model="query.remark" placeholder="请输入备注"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6" align="center">
              <rrOperation :crud="crud"/>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu>
      <!-- 表格配置 -->
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header"  @tabSave="tabSave" @pit="pit" />
      </el-dialog>

      <!--表格渲染-->
      <el-table ref="table"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                border v-loading="crud.loading"
                :data="crud.data"
                size="small"
                style="width: 100%;"
                v-if="isShowTable"
                @header-dragend="changeColWidth"
                @contextmenu.native="showMenu"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55"/>
        <el-table-column type="index" width="60" label="序号"/>
<!--        <el-table-column-->
<!--          v-if="item.visible"-->
<!--          v-for="(item, index) in crud.header"-->
<!--          :key="`col_${index}`"-->
<!--          :prop="item.prop"-->
<!--          :label="columnLabel(item)"-->
<!--          :width="item.width + 'px'"-->
<!--          :data-porp='item.prop'-->
<!--          @contextmenu.native="showMenu"-->
<!--          @header-dragend="changeColWidth"-->
<!--        >-->
<!--          &lt;!&ndash; 自定义渲染模版 &ndash;&gt;-->
<!--          <template slot-scope="scope">-->
<!--            &lt;!&ndash; 当列key为 sort 时，渲染一个手柄icon &ndash;&gt;-->
<!--            <template v-if="item.prop =='sort'">-->
<!--              <div class="handle_move">-->
<!--                <i :class="scope.row['sort']" />-->
<!--              </div>-->
<!--            </template>-->
<!--            <template v-else>-->
<!--              <span v-if="item.type == 1" style="margin-left: 0px">{{scope.row[`${item.prop}`]}}</span>-->
<!--              <span v-if="item.type == 2" style="margin-left: 0px">{{ parseTime(scope.row[`${item.prop}`])}}</span>-->
<!--              <span v-if="item.type == 3" style="margin-left: 0px">{{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}</span>-->
<!--            </template>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column width="130" v-if="columns.visible('busDate')" prop="busDate" label="业务日期">
          <template slot-scope="scope">
            <span>
              {{parseDate(scope.row.busDate)}}
            </span>
          </template>
        </el-table-column>
        <el-table-column width="160" v-if="columns.visible('feeOrderCode')" prop="feeOrderCode" label="费用单据编号"/>
        <el-table-column width="130" v-if="columns.visible('sourceType')" prop="sourceType" label="费用收支类型">
          <template slot-scope="scope">
            <span v-for="item in dict.t_fee_cancel_flow_source_type" v-if="item.value == scope.row.sourceType">{{
                item.label
              }}</span>
          </template>
        </el-table-column>
        <el-table-column width="160" v-if="columns.visible('sourceCode')" prop="sourceCode" label="费用收支单据编号"/>
        <el-table-column width="160" v-if="columns.visible('payBackType')" prop="payBackType" label="费用收支方式">
          <template slot-scope="scope">
            <span v-for="item in dict.t_fee_back_type" v-if="item.value == scope.row.payBackType">{{
                item.label
              }}</span>
          </template>
        </el-table-column>
        <el-table-column width="160" v-if="columns.visible('customerName')" prop="customerName" label="往来单位"/>
        <el-table-column width="100" v-if="columns.visible('deptName')" prop="deptName" label="部门"/>
        <el-table-column width="100" v-if="columns.visible('userName')" prop="userName" label="人员"/>
        <el-table-column width="160" v-if="columns.visible('taxAmount')" prop="taxAmount" label="收支金额"/>
        <el-table-column width="160" v-if="columns.visible('remark')" prop="remark" label="备注"/>
      </el-table>
      <!--分页组件-->
      <pagination/>
    </div>
  </div>
</template>

<script>
import crudFeeCancelFlow from '@/api/erp/feeCancelFlow'
import CRUD, {crud, form, header, presenter} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

import { publicListKey } from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
import {tablemixins} from "@/mixins/tablemixins";
import  jTableColumnConfig  from "@/components/jTableColumnConfig/jTableColumnConfig";

// crud交由presenter持有
const defaultCrud = CRUD({
  title: '费用核销流水',
  url: 'api/feeCancelFlow',
  sort: 'id,desc',
  crudMethod: {...crudFeeCancelFlow}
})
const defaultForm = {
  id: null,
  type: null,
  busDate: null,
  sourceType: null,
  sourceId: null,
  sourceCode: null,
  feeOrderId: null,
  feeOrderCode: null,
  customerId: null,
  customerCode: null,
  customerName: null,
  isContact: null,
  deptId: null,
  deptCode: null,
  deptName: null,
  userId: null,
  userCode: null,
  userName: null,
  payBackType: null,
  taxAmount: null,
  seq: null,
  remark: null,
  createUserId: null,
  createUserCode: null,
  createUserName: null,
  createTime: null,
  updateUserId: null,
  updateUserCode: null,
  updateUserName: null,
  updateTime: null
}
export default {
  name: 'FeeCancelFlow',
  components: {pagination, crudOperation, rrOperation, udOperation,jTableColumnConfig},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),publicListKey,tablemixins],
  dicts: ['t_fee_back_type', 't_fee_cancel_flow_source_type'],
  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      permission: {
        add: ['admin', 'feeCancelFlow:add'],
        edit: ['admin', 'feeCancelFlow:edit'],
        del: ['admin', 'feeCancelFlow:del'],
        import: ['admin', 'feeCancelFlow:import'],
        export: ['admin', 'feeCancelFlow:export'],
        copy: ['admin', 'feeCancelFlow:copy'],
        upload: ['admin', 'feeCancelFlow:upload'],
        download: ['admin', 'feeCancelFlow:download'],
      },
      rules: {
        type: [
          {required: true, message: '类型(1:银行 2:账扣)不能为空', trigger: 'blur'}
        ],
        payBackType: [
          {required: true, message: '费用收支方式(1:银行 2:账扣)不能为空', trigger: 'blur'}
        ]
      },
      userParams: {
        deptId: null
      }
    }
  },
  watch: {},
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    changeDept(e) {
      const {id} = e
      this.userParams.deptId = id
    },
    getValue(e) {
      this.query.startTime = this.query.dataExtent[0]
      this.query.endTime = this.query.dataExtent[1]
    },
  }
}
</script>

<style scoped>
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
</style>
